﻿package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.ResDetail;
public class ResDetailXmlparse {

	private static  ResDetail resDetailBean = null;
	
	public static ResDetail getXml(InputStream inSteam) throws Exception{
		
		XmlPullParser xmpparse = Xml.newPullParser();   //得到解释器
		xmpparse.setInput(inSteam, "UTF-8");           //设置解释流
		int code = xmpparse.getEventType();            //得到节点信息
		while(code != XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_TAG:
				if("restaurant".equals(xmpparse.getName())){
					resDetailBean = new ResDetail();
				}
				if(resDetailBean!=null){
					if("id".equals(xmpparse.getName())){
						String id = xmpparse.nextText();
						resDetailBean.setId(Integer.parseInt(id));
					}
					if("title".equals(xmpparse.getName())){
						String title = xmpparse.nextText();
						resDetailBean.setTitle(title);
					}
					if("tel".equals(xmpparse.getName())){
						String tel = xmpparse.nextText();
						resDetailBean.setTel(tel);
					}
					if("address".equals(xmpparse.getName())){
						String address = xmpparse.nextText();
						resDetailBean.setAddress(address);
					}
					if("vouch".equals(xmpparse.getName())){
						String vouch = xmpparse.nextText();
						resDetailBean.setVouch(Integer.parseInt(vouch));
					}
					if("average".equals(xmpparse.getName())){
						String average = xmpparse.nextText();
						resDetailBean.setAverage(average);
					}
					if("star".equals(xmpparse.getName())){
						String star = xmpparse.nextText();
						resDetailBean.setStar(star);
					}
					if("dish".equals(xmpparse.getName())){
						String dish = xmpparse.nextText();
						resDetailBean.setDish(dish);
					}
					if("opening".equals(xmpparse.getName())){
						String opening = xmpparse.nextText();
						resDetailBean.setOpening(opening);
					}
					if("traffic".equals(xmpparse.getName())){
						String traffic = xmpparse.nextText();
						resDetailBean.setTraffic(traffic);
					}
					if("park".equals(xmpparse.getName())){
						String park = xmpparse.nextText();
						resDetailBean.setPark(park);
					}
					if("maindish".equals(xmpparse.getName())){
						String maindish = xmpparse.nextText();
						resDetailBean.setMaindish(maindish);
					}
					if("intro".equals(xmpparse.getName())){
						String intro = xmpparse.nextText();
						resDetailBean.setIntro(intro);
					}
					if("seat".equals(xmpparse.getName())){
						String seat = xmpparse.nextText();
						resDetailBean.setSeat(seat);
					}
					if("location".equals(xmpparse.getName())){
						String location = xmpparse.nextText();
						resDetailBean.setLocation(location);
					}
					if("area".equals(xmpparse.getName())){
						String area = xmpparse.nextText();
						resDetailBean.setArea(area);
					}
					if("recomment".equals(xmpparse.getName())){
						String recomment  = xmpparse.nextText();
						resDetailBean.setRecomment(recomment);
					}
					if("discount".equals(xmpparse.getName())){
						String discount  = xmpparse.nextText();
						resDetailBean.setDiscount(Float.parseFloat(discount));
					}
					if("comment".equals(xmpparse.getName())){
						String comment  = xmpparse.nextText();
						resDetailBean.setComment(Integer.parseInt(comment));
					}
					if("blog-cnt".equals(xmpparse.getName())){
						String blog  = xmpparse.nextText();
						resDetailBean.setBlog(Integer.parseInt(blog));
					}
					if("pepsi".equals(xmpparse.getName())){
						String pepsi  = xmpparse.nextText();
						resDetailBean.setPepsi(Integer.parseInt(pepsi));
					}
				}	
				break;
			}
			code = xmpparse.next();
		}
		inSteam.close();
		return resDetailBean;
	} 
}
